<template>
  <div>
    <!-- 标题栏 -->
    <van-nav-bar
      title="不凡"
      left-text="返回"
      left-arrow
      fixed
      @click-left="onClickLeft"
    />
    <div class="save-content">
      <div class="item">
         <input type="text" placeholder="姓名" v-model="userName">
      </div>
       <div class="item">
         <input type="text" placeholder="手机号码" v-model="telNumber">
       </div>
        <div class="item" @click="pickerClick">
          <input type="text" readonly placeholder="省份、城市、区县" v-model="address">
        </div>
        <div class="item">
          <input type="text" placeholder="详细地址,如楼道、楼盘号等" v-model="detailadress">
        </div>
          <van-checkbox v-model="checked" shape="square">设为默认地址</van-checkbox>
         <div class="add" @click="addAction">保存</div>
    </div>
    <!-- 级联选择器 -->
    <div class="picker" >
      <van-popup v-model="show" position="bottom" :style="{ height: '45%' }">
        <van-area title="标题" :area-list="this.area" confirm-button-text @confirm='confirm' />
      </van-popup>
    </div>
    </div>
</template>
<script>
import { saveAction } from "@/api/my/address.js";
import area from "@/assets/area.js"
export default {
  data() {
    return {
      //地址
      address: "",
      //是新增还是修改 新增不传 修改穿id
      // addressId: 118,
      addressId:'',
      //是否默认选中
      checked: false,
      //详细地址
      detailadress: "",
      openId: "",
      //电话
      telNumber:'',
      //名字
      userName: "",
      area,  
      show:false, 
    };
  },
  methods: {
    getSaveAction(){
      saveAction({
          address:this.address,
          addressId:this.addressId,
          checked:this.checked,
          detailadress:this.detailadress,
          openId:localStorage.getItem('openId'),
          telNumber:this.telNumber,
          userName:this.userName
        }).then(res=>{
          console.log(res)
        })
    },
      //返回上一页
      onClickLeft(){
          this.$router.go(-1);
      },
      pickerClick(){
        this.show=true;
      },
      addAction(){
        //保存
        this.getSaveAction();
     },
      //确定选中
      confirm(item){
        // console.log(item)
       this.address=item[0].name+item[1].name+item[2].name;
       this.show=false;
      }
  },
  created() {
    this.getSaveAction();
  },
};
</script>
<style lang="scss" scoped>
.save-content{
  position: relative;
    margin-top: 50px;
    // height:700px;
    background-color: #fff;
  .item{
    width: 100%;
    height: 55px;
    border-bottom: 2px solid #f4f4f4;
    input{
    display: block;
    box-sizing: border-box;
    width: 100%;
    margin: 0;
    padding:0 30px;
    line-height:55px;
    background-color: transparent;
    border: 0;
    font-size: 14px;
    }
    
  }  
  .van-checkbox{
      padding: 0 10px;
    margin-top: 10px;
    font-size: 14px;
    } 
  .add{
    width: 100%;
    height:50px;
    text-align: center;
    line-height: 50px;
    color: #fff;
    background-color:#b4282d;
    position: fixed;
    bottom: 0;
    font-size:16px;
  }
}

</style>